/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.com.apresentacao.matricula;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import src.com.negocio.matricula.AgendaNivel;
import src.com.negocio.pedagogico.CadastrarIdioma;
import src.com.negocio.infraEstrutura.CadastrarUnidade;
import src.com.negocio.pedagogico.CadastrarAluno;
import src.com.negocio.pedagogico.CadastrarTurma;

/**
 *
 * @author Giane
 */
public class AgendarNivelamento extends javax.swing.JFrame {

    /**
     * Creates new form AgendarNivelamento
     */
    public AgendarNivelamento() throws SQLException {
        initComponents();
        CadastrarIdioma c = new CadastrarIdioma();
        for (int i = 0; i < c.consultaIdioma().size(); i++) {
            i_idioma.addItem(c.consultaIdioma().get(i));
        }
        CadastrarUnidade x = new CadastrarUnidade();
        for (int i = 0; i < x.consultaUnidade().size(); i++) {
            unidade.addItem(x.consultaUnidade().get(i));
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        d_dia = new javax.swing.ButtonGroup();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        nmAluno = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        i_idioma = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        hrInicio = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        hrFim = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        unidade = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        numCPF = new javax.swing.JFormattedTextField();
        prof = new javax.swing.JTextField();
        data = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jInternalFrame1.setTitle("Agendar Teste Nivelamento");
        jInternalFrame1.setVisible(true);

        jLabel1.setText("Aluno");

        nmAluno.setName("nmAluno"); // NOI18N
        nmAluno.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nmAlunoMouseClicked(evt);
            }
        });

        jLabel2.setText("CPF: ");

        jLabel3.setText("Idioma: ");

        i_idioma.setName("i_idioma"); // NOI18N
        i_idioma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                i_idiomaActionPerformed(evt);
            }
        });

        jLabel4.setText("Data:");

        jLabel5.setText("Horário: ");

        hrInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00" }));
        hrInicio.setName("hrInicio"); // NOI18N

        jLabel6.setText("às");

        hrFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00" }));
        hrFim.setName("htFim"); // NOI18N

        jLabel7.setText("Professor: ");

        jLabel8.setText("Unidade: ");

        unidade.setName("unidade"); // NOI18N

        jButton1.setText("Agendar");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        try {
            numCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        numCPF.setName("cpf"); // NOI18N
        numCPF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numCPFActionPerformed(evt);
            }
        });

        prof.setName("prof"); // NOI18N

        data.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jInternalFrame1Layout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addGap(9, 9, 9)
                            .addComponent(prof, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jLabel8)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(unidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame1Layout.createSequentialGroup()
                            .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addGap(35, 35, 35)
                            .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(nmAluno)
                                .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(numCPF, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                        .addComponent(data))
                                    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                            .addGap(10, 10, 10)
                                            .addComponent(jLabel5)
                                            .addGap(8, 8, 8))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup()
                                            .addGap(11, 11, 11)
                                            .addComponent(jLabel3)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                                    .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(i_idioma, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                            .addComponent(hrInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jLabel6)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(hrFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nmAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(i_idioma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(numCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(hrInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(hrFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(prof, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(unidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        nmAluno.getAccessibleContext().setAccessibleName("nmAluno");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void numCPFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numCPFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_numCPFActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        //SALVAR OS DADOS
        String nome = nmAluno.getText().toString();
        String CPF = numCPF.getText().toString();
        String idioma = i_idioma.getSelectedItem().toString();
        String d_data = data.getText().toString();
        String horaInicio = hrInicio.getSelectedItem().toString();
        String horaFim = hrFim.getSelectedItem().toString();
        String professor = prof.getText().toString();
        String uni = unidade.getSelectedItem().toString();

        CadastrarAluno C = new CadastrarAluno();
        CadastrarTurma B = new CadastrarTurma();
        AgendaNivel A = new AgendaNivel();
        try {

            if (C.VerificarAluno(nome, CPF).equals("1")) {
                if (B.VerificarProfessor(professor).equals("1")) {
                    if (A.VerificarAgendamento(d_data, horaInicio, horaFim, professor).equals("0")) {
                        A.insereAgendaNivel(professor, nome, CPF, idioma, uni, d_data, horaInicio, horaFim);
                        javax.swing.JDialog inf = new javax.swing.JDialog();
                        inf.setSize(250, 150);
                        javax.swing.JOptionPane.showMessageDialog(inf, "Agendamento realizado com sucesso!", "Informação", javax.swing.JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        javax.swing.JDialog inf = new javax.swing.JDialog();
                        inf.setSize(250, 150);
                        javax.swing.JOptionPane.showMessageDialog(inf, "Choque de horário!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                    }
                } else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "O professor informado não existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                }
            }else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "O aluno informado não existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                }
        } catch (SQLException ex) {
            Logger.getLogger(AgendarNivelamento.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButton1MouseClicked

    private void nmAlunoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nmAlunoMouseClicked
        // TODO add your handling code here:
        //System.out.println(nmAluno.getText().toString());
    }//GEN-LAST:event_nmAlunoMouseClicked

    private void i_idiomaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_i_idiomaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_i_idiomaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AgendarNivelamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AgendarNivelamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AgendarNivelamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AgendarNivelamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new AgendarNivelamento().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(AgendarNivelamento.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup d_dia;
    private javax.swing.JFormattedTextField data;
    private javax.swing.JComboBox hrFim;
    private javax.swing.JComboBox hrInicio;
    private javax.swing.JComboBox i_idioma;
    private javax.swing.JButton jButton1;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField nmAluno;
    private javax.swing.JFormattedTextField numCPF;
    private javax.swing.JTextField prof;
    private javax.swing.JComboBox unidade;
    // End of variables declaration//GEN-END:variables
}
